//
//  FViewController.m
//  页面之间传值
//
//  Created by MAC on 2018/8/27.
//  Copyright © 2018年 MAC. All rights reserved.
//

#import "FViewController.h"
//导入B页面头文件
#import "F-2-ViewController.h"

@interface FViewController ()
//声明全局UI指针
@property (nonatomic,strong) UILabel *label;
@property (nonatomic,strong) UIButton *btn;
@end

@implementation FViewController
//UILabel的懒加载
- (UILabel *)label
{
    if (_label == nil) {
        _label = [[UILabel alloc]initWithFrame:CGRectMake((self.view.frame.size.width-200)/2, 100, 200, 40)];
        _label.backgroundColor = [UIColor blackColor];
        _label.textColor = [UIColor whiteColor];
        _label.font = [UIFont systemFontOfSize:20];
    }
    return _label;
}
//UIButton的懒加载
- (UIButton *)btn
{
    if (_btn == nil) {
        _btn = [UIButton buttonWithType:UIButtonTypeCustom];
        _btn.backgroundColor = [UIColor redColor];
        _btn.frame = CGRectMake((self.view.frame.size.width-200)/2, _label.frame.origin.y+_label.frame.size.height+40, 200, 40);
        [_btn setTitle:@"跳转B页面" forState:UIControlStateNormal];
        [_btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        //点击事件
        [_btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    //把UI指针添加到View视图中
    [self.view addSubview:self.label];
    [self.view addSubview:self.btn];
}

//button点击事件 -- 跳转到页面二
- (void)btnClick
{
    //声明指针，并初始化
    F_2_ViewController *f_2_VC = [[F_2_ViewController alloc]init];
    //通知传值 - 添加监听等待页面二的传值
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notHandle:) name:@"notify" object:nil];
    //跳转B页面
    [self.navigationController pushViewController:f_2_VC animated:YES];
    
//    [self presentViewController:f_2_VC animated:YES completion:nil];
}

//接收到通知之后的处理 - 参数1：通知
- (void)notHandle:(NSNotification *)not
{
    //把获取的传值，赋值给标签
    self.label.text = not.userInfo[@"not"];
}
@end
